<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Promise.prototype.then</title>
</head>

<body>

    <script>
        //创建promise对象
        const p = new Promise((resolve, reject) => {
            setTimeout(() => {
                resolve('用户数据');
                // reject('失败了，出错了！');
            }, 1000);
        });

        //调用then方法  then方法的返回结果是Promise 对象，对象状态由回调函数的执行结果决定
        //1.如果回调函数中返回的结果是 非promise类型的属性，状态为成功，返回值为对象的成功的值
        const result = p.then(value => {
            console.log(value);
            //1.非promise类型的属性
            // return "123";
            //2.是promise对象
            // return new Promise((resolve, reject) => {
            //     // resolve('ok');
            //     reject('error');
            // })
            //3.抛出错误
            // throw new Error('出错了!');
            throw '出错啦!';


        }, reason => {
            console.warn(reason);
        })



        //链式调用
        p.then(value => {

        }, reason => {

        }).then(value => {

        }, reason => {

        })



        console.log(result);


    </script>


</body>

</html>